<!doctype html>
<html>
<head>
<meta charset="utf-8">

<title>canvas的变换3-以图形为圆心</title>
<style>
body {background:black; text-align:center;}
#c1 {background:white;}
</style>
<script>
//角度->弧度
function d2a(n)
{
	return n*Math.PI/180;
}

window.onload=function ()
{
	var oC=document.getElementById('c1');
	var gd=oC.getContext('2d');

	//参考矩形是自己
	gd.strokeRect(200, 75, 200, 150); 
	
	gd.translate(300,150);//位移  gd.translate(l+w/2, t+h/2);
	 gd.rotate(d2a(30)); //旋转度数  
	
	gd.strokeStyle="red";
	gd.strokeRect(-100, -75, 200, 150);//绘制矩形  gd.strokeRect(-w/2, -h/2, w, h);
	
	//画出画布
	//gd.fillStyle='rgba(255,0,0,0.3)';
	//gd.fillRect(0,0,oC.width,oC.height);
};
</script>
</head>

<body>
<canvas id="c1" width="800" height="600"></canvas>
</body>
</html>





